package com.guoq.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.guoq.constant.Configration;
import com.guoq.pojo.EUDataGridResult;
import com.guoq.pojo.Item;
import com.guoq.pojo.ItemExample;
import com.guoq.pojo.Result;
import com.guoq.service.IItemService;


/**
 * 
 * <P>类名称:ItemController
 * <P>类描述: 商品 Controller
 * <P>创建人:郭强  
 * <P>修改人:XXX 
 * <P>修改时间:2017年7月20日 上午11:59:04
 * <P>修改备注: 
 * @version 1.0.0
 * Copyright(c)2017西部在线-版权所有
 */
@Controller
@RequestMapping("/item")
public class ItemController {
	@Resource
	private IItemService itemService;
	
	@RequestMapping("/toadd")
	public String toIndex(HttpServletRequest request,Model model){
		return "/item/add";
	}
	
	@RequestMapping("/toedit")
	public String toedit(HttpServletRequest request,Model model){
		return "/item/edit";
	}
	
	/**
	 * 
	 *<P>开发者:郭强
	 *<P>方法名: getItemById
	 *<P>描述: 根据id获取类目信息
	 *@param request
	 *@param model
	 *@return   
	 *@exception   
	 *@since  1.0.0
	 */
	@RequestMapping("/getItemById")
	@ResponseBody
	public Item getItemById(HttpServletRequest request,Model model){
		int id = Integer.parseInt(request.getParameter("id"));
		Item item = this.itemService.getItemById(id);
		return item;
	}
	
	/**
	 * 
	 *<P>开发者:郭强
	 *<P>方法名: list
	 *<P>描述: 获取商品列表（不分页）
	 *@param request
	 *@param model
	 *@return   
	 *@exception   
	 *@since  1.0.0
	 */
	@RequestMapping("/list")
	@ResponseBody
	public List<Item> list(HttpServletRequest request,Model model){
		
		List<Item> list = this.itemService.getItemList();
		return list;
	}
	
	/**
	 * 
	 *<P>开发者:郭强
	 *<P>方法名: getItemList
	 *<P>描述: 获取商品列表（分页）
	 *@param page
	 *@param rows
	 *@return   
	 *@exception   
	 *@since  1.0.0
	 */
	@RequestMapping(value="/pagelist")
	@ResponseBody
	public EUDataGridResult pagelist(HttpServletRequest request, Integer page, Integer rows) {
		
		String sid = request.getParameter("sid");
		EUDataGridResult result = itemService.getItemList(page, rows, sid);
		return result;
	}
	
	/**
	 * 
	 *<P>开发者:郭强
	 *<P>方法名: add
	 *<P>描述: 新增
	 *@param item
	 *@return   
	 * @throws Exception 
	 *@exception   
	 *@since  1.0.0
	 */
	@RequestMapping(value="/save", method=RequestMethod.POST)
	@ResponseBody
	public Result add(Item item) throws Exception{
		
		Result result = this.itemService.createItem(item);
		return result;
	} 
	
	/**
	 * 
	 *<P>开发者:郭强
	 *<P>方法名: update
	 *<P>描述: 编辑
	 *@param item
	 *@return
	 *@throws Exception   
	 *@exception   
	 *@since  1.0.0
	 */
	@RequestMapping(value="/update", method=RequestMethod.POST)
	@ResponseBody
	public Result update(Item item) throws Exception{
		
		Result result = this.itemService.updateItem(item);
		return result;
	} 
	
	/**
	 * 
	 *<P>开发者:郭强
	 *<P>方法名: delete
	 *<P>描述:	删除 
	 *@param id
	 *@return
	 *@throws Exception   
	 *@exception   
	 *@since  1.0.0
	 */
	@RequestMapping(value="/delete")
	@ResponseBody
	public Result delete(Item record) throws Exception{
		
		Result result = this.itemService.delete(record);
		return result;
	}
	
}
